/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package pe.edu.pucp.sistemasInf.controller;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.logging.Level;
import java.util.logging.Logger;

/**
 *
 * @author Cesar
 */
public class MySQLDAOPerfil implements DAOPerfil{

    @Override
    public String getNamePerfil(int idPerfil) {
        
        Connection conn = null;
        PreparedStatement pstmt = null;
        ResultSet rs=null;
        //int result  = 0;
        try {
            //Paso 1: Registramos el driver
            DriverManager.registerDriver(new com.mysql.jdbc.Driver());
            //Paso 2: Obtenemos la conexión            
            conn = new DBConfig().getConnection();
            //Paso 3: Preparamos la sentencia
            pstmt = conn.prepareStatement(
                "SELECT nombrePerfil FROM perfil WHERE idPerfil=?");
            
            pstmt.setInt(1, idPerfil);
            rs=pstmt.executeQuery();
            
            while (rs.next())
                return rs.getString("nombrePerfil");
                
            
        } catch (SQLException ex) {
            Logger.getLogger(MySQLDAOCliente.class.getName()).log(Level.SEVERE, null, ex);
        }
        finally {
            try {//Paso 5: Cerramos la conexión
            conn.close(); } catch(Exception g) {g.printStackTrace();}
        }
        
        return null;
    }
    
    
    
}
